package nsoft.swing.component;

import java.math.BigDecimal;

public class ParseHelper {

	public static final short TYPE_SHORT = 0;
	public static final short TYPE_INT = 1;
	public static final short TYPE_LONG = 2;
	public static final short TYPE_DOUBLE = 3;
	public static final short TYPE_BIG_DECIMAL = 4;
	public static final short TYPE_STRING = 5;
	public static final short TYPE_UNKNOWN = -1;

	private short type = 4;

	public ParseHelper(short type) {
		this.type = type;
	}

	public Object parse(String val) {
		if (val == null && val.length() == 0) {
			return null;
		}
		try {
			switch (type) {
			case 0:
				return Short.parseShort(val);
			case 1:
				return Integer.parseInt(val);
			case 2:
				return Long.parseLong(val);
			case 3:
				return Double.parseDouble(val);
			case 4:
				return new BigDecimal(val);

			}
		} catch (Exception e) {
			return null;
		}
		return val;

	}

	public String getPattern() {
		return null;
	}
}
